/**
 * Created by user on 2018/12/6.
 */
const os = require('os')

function getPlatform() {
    let _platform
    const platform = os.platform()
    if (platform === 'darwin')
        _platform = 'mac'
    else if (platform === 'linux')
        _platform = 'linux'
    else if (platform === 'win32')
        _platform = os.arch() === 'x64' ? 'win64' : 'win32'
    return _platform
}

function getPuppeteerConfig(opt = {}) {
    let platform = getPlatform()
    let exc = platform === 'linux' ? { args: ['--no-sandbox'] } : {}
    return Object.assign({}, {
        timeout: 15000,
        //如果是访问https页面 此属性会忽略https错误
        ignoreHTTPSErrors: true,
        // 打开开发者工具, 当此值为true时, headless总为false
        devtools: false,
        // 关闭headless模式, 不会打开浏览器
        headless: true
    }, exc, opt)
}

function getPageUrl(rid, isTest) {
    return `https://live.dragongap.cn/live/test?id=${rid}&test=${isTest ? 1 : 0}`
}


module.exports = {
    getPlatform,
    getPuppeteerConfig,
    getPageUrl
}